<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>业务表管理</title>
	<script type="text/javascript">
		$(document).ready(function() {
			layui.use('table', function(){
				let table = layui.table;
				table.init('layui-filter-table1',{
					escape : false
					,height: getLayuiTableHeight()
					,className: 'layui-table-custom'
					,css: [
						// 设置单元格样式
						'.layui-table{background:#fcfcfc;}',
						'.layui-input{height:34px;}',
						'.layui-table-cell input{border:none;}',
						'.layui-table-cell:has(input[type="text"]){padding:0px}'

					].join('')

					,done: function (res,curr,count){
						// 清空表格内容
						$('#layui-table-id1').children().remove();
						// 为特定列的单元格移除自定义样式
						// $("td[data-field='a.javaType'],td[data-field='a.queryType'],td[data-field='a.showType']").each(function(){
						//     // 在每个目标单元格中找到并移除其layui-table-cell类
						//     $(this).find('div.layui-table-cell').removeClass('layui-table-cell');
						// });
					}
				});
			});
			$("#inputForm").validate({
				submitHandler: function (form) {
					// 遍历所有类型为checkbox的input元素
					$("input[type=checkbox]").each(function(){
					    // 检查当前checkbox后面的div元素是否具有类名'layui-form-checked'
					    if($(this).next('div').hasClass('layui-form-checked')){
					        // 如果具有该类名，说明checkbox被选中，设置其值为"1"
					        $(this).val("1");
					    }else{
					        // 如果不具有该类名，说明checkbox未被选中，在当前checkbox后插入一个隐藏的input元素，值为"0"
					        $(this).after('<input type="hidden" name="' + $(this).attr("name") + '" value="0">');
					    }
					});
					form.submit();
				},
				errorClass: 'validation-invalid-label',
				highlight: function(element, errorClass) {
					$(element).removeClass(errorClass);
				},
				errorPlacement: function (error, element) {
					validateErrorPlacement(error, element);
				}
			});

		});
	</script>
	<style>
		dd{
			margin-bottom: 0;
		}
	</style>
</head>
<body>
	<ul class="nav nav-tabs nav-tabs-bottom mb-0">
		<li class="nav-item"><a class="nav-link" href="${ctx}/gen/genTable/">业务表列表</a></li>
		<li class="nav-item"><a class="nav-link active" href="${ctxAdmin}/gen/genTable/form?id=${genTable.id}&name=${genTable.name}">业务表<shiro:hasPermission name="gen:genTable:edit">${not empty genTable.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="gen:genTable:edit">查看</shiro:lacksPermission></a></li>
	</ul>
	<sys:message content="${message}"/>
	<div class="content">
		<div class="card">
			<div class="card-body">
				<c:choose>
					<c:when test="${empty genTable.name}">
						<form:form id="inputForm" method="post"  onsubmit=""
							modelAttribute="genTable" action="${ctxAdmin}/gen/genTable/form" >
							<form:hidden path="id"/>
							<div class="form-group row">
								<label class="col-sm-3 col-form-label">表名</label>
								<div class="col-sm-8">
									<form:select path="name" class="form-control ">
										<form:options items="${tableList}" itemLabel="nameAndComments" itemValue="name" htmlEscape="false"/>
									</form:select>
								</div>
							</div>
							<div class="form-group row">
								<div class="col-sm-9 ml-auto">
									<button type="submit" class="btn btn-primary"><i class="icon-database-check mr-2"></i>下一步</button>
									<button type="button" class="btn btn-light" onclick="history.go(-1)"><i class="icon-database-arrow mr-2"></i>返 回</button>
								</div>
							</div>
						</form:form>
					</c:when>
					<c:otherwise>
						<form:form id="inputForm" method="post" onsubmit="return false"
							modelAttribute="genTable" action="${ctxAdmin}/gen/genTable/save">
							<form:hidden path="id"/>
							<fieldset><legend>基本信息</legend></fieldset>
							<div class="row">
								<div class="col-sm-6">
									<div class="form-group row">
										<label class="col-sm-3 col-form-label">表名</label>
										<div class="col-sm-8">
											<form:input path="name" htmlEscape="false" maxlength="200" cssClass="form-control required" readonly="true"/>
										</div>
									</div>
									<div class="form-group row">
										<label class="col-sm-3 col-form-label">说明</label>
										<div class="col-sm-8">
											<form:input path="comments" htmlEscape="false" maxlength="200" cssClass="form-control required"/>
										</div>
									</div>
									<div class="form-group row">
										<label class="col-sm-3 col-form-label">类名</label>
										<div class="col-sm-8">
											<form:input path="className" htmlEscape="false" maxlength="200" cssClass="form-control required"/>
										</div>
									</div>
								</div>
								<div class="col-sm-6">
									<div class="form-group row">
										<label class="col-sm-3 col-form-label">父表表名</label>
										<div class="col-sm-8">
											<form:select path="parentTable" cssClass="input-xlarge">
												<form:option value="">无</form:option>
												<form:options items="${tableList}" itemLabel="nameAndComments" itemValue="name" htmlEscape="false"/>
											</form:select>
											&nbsp;当前表外键：
											<form:select path="parentTableFk" cssClass="input-xlarge">
												<form:option value="">无</form:option>
												<form:options items="${genTable.columnList}" itemLabel="nameAndComments" itemValue="name" htmlEscape="false"/>
											</form:select>
											<span class="help-inline">如果有父表，请指定父表表名和外键</span>
										</div>
									</div>
									<div class="form-group row hide">
										<label class="col-sm-3 col-form-label">备注:</label>
										<div class="col-sm-8">
											<form:textarea path="remarks" htmlEscape="false" rows="4" maxlength="200" cssClass="form-control"/>
										</div>
									</div>
								</div>
							</div>
							<fieldset><legend>字段列表</legend></fieldset>
							<div class="form-group row">
									<table id="layui-table-id1" lay-filter="layui-filter-table1" lay-size="" style="display: none;">
										<thead>
											<tr>
												<th lay-data="{field:'a.name'}" title="数据库字段名">列名</th>
												<th lay-data="{field:'a.comments'}" title="默认读取数据库字段备注">说明</th>
												<th lay-data="{field:'a.jdbcType'}" title="数据库中设置的字段类型及长度">物理类型</th>
												<th lay-data="{field:'a.javaType'}" title="实体对象的属性字段类型">Java类型</th>
												<th lay-data="{field:'a.javaField'}" title="实体对象的属性字段（对象名.属性名|属性名2|属性名3，例如：用户user.id|name|loginName，属性名2和属性名3为Join时关联查询的字段）">Java属性名称 <i class="icon-question-sign"></i></th>
												<th lay-data="{field:'a.isPk',width:30,align:'center'}" title="是否是数据库主键">主键</th>
												<th lay-data="{field:'a.isNull',width:30,align:'center'}" title="字段是否可为空值，不可为空字段自动进行空值验证">可空</th>
												<th lay-data="{field:'a.isInsert',width:30,align:'center'}" title="选中后该字段被加入到insert语句里">插入</th>
												<th lay-data="{field:'a.isEdit',width:30,align:'center'}" title="选中后该字段被加入到update语句里">编辑</th>
												<th lay-data="{field:'a.isList',width:30,align:'center'}" title="选中后该字段被加入到查询列表里">列表</th>
												<th lay-data="{field:'a.isQuery',width:30,align:'center'}" title="选中后该字段被加入到查询条件里">查询</th>
												<th lay-data="{field:'a.queryType'}" title="该字段为查询字段时的查询匹配放松">查询匹配方式</th>
												<th lay-data="{field:'a.showType'}" title="字段在表单中显示的类型">显示表单类型</th>
												<th lay-data="{field:'a.dictType'}" title="显示表单类型设置为“下拉框、复选框、点选框”时，需设置字典的类型">字典类型</th>
												<th lay-data="{field:'a.sort',width:60,align:'center'}">排序</th>
											</tr>
										</thead>
										<tbody>
										<c:forEach items="${genTable.columnList}" var="column" varStatus="vs">
											<tr${column.delFlag eq '1'?' class="error" title="已删除的列，保存之后消失！"':''}>
												<td>
													<input type="hidden" name="columnList[${vs.index}].id" value="${column.id}"/>
													<input type="hidden" name="columnList[${vs.index}].delFlag" value="${column.delFlag}"/>
													<input type="hidden" name="columnList[${vs.index}].genTable.id" value="${column.genTable.id}"/>
													<input type="hidden" name="columnList[${vs.index}].name" value="${column.name}"/>${column.name}
												</td>
												<td>
													<input lay-ignore type="text" name="columnList[${vs.index}].comments" value="${column.comments}" maxlength="200" class="required form-control"/>
												<td>
													<input type="hidden" name="columnList[${vs.index}].jdbcType" value="${column.jdbcType}"/>${column.jdbcType}
												</td>
												<td>
													<select name="columnList[${vs.index}].javaType" class="required nativeSelect" lay-append-to="body">
														<c:forEach items="${config.javaTypeList}" var="dict">
															<option value="${dict.value}" ${dict.value==column.javaType?'selected':''} title="${dict.description}">${dict.label}</option>
														</c:forEach>
													</select>
												</td>
												<td>
													<input type="text" name="columnList[${vs.index}].javaField" value="${column.javaField}" maxlength="200" class="required form-control"/>
												</td>
												<td>
													<input type="checkbox" name="columnList[${vs.index}].isPk" value="${column.isPk}" ${column.isPk eq '1' ? 'checked' : ''}/>
												</td>
												<td>
													<input type="checkbox" name="columnList[${vs.index}].isNull" value="${empty column.isNull ? '0' : column.isNull}" ${column.isNull eq '1' ? 'checked' : ''}/>
												</td>
												<td>
													<input type="checkbox" name="columnList[${vs.index}].isInsert" value="1" ${column.isInsert eq '1' ? 'checked' : ''}/>
												</td>
												<td>
													<input type="checkbox" name="columnList[${vs.index}].isEdit" value="1" ${column.isEdit eq '1' ? 'checked' : ''}/>
												</td>
												<td>
													<input type="checkbox" name="columnList[${vs.index}].isList" value="1" ${column.isList eq '1' ? 'checked' : ''}/>
												</td>
												<td>
													<input type="checkbox" name="columnList[${vs.index}].isQuery" value="1" ${column.isQuery eq '1' ? 'checked' : ''}/>
												</td>
												<td>
													<select name="columnList[${vs.index}].queryType" class="required nativeSelect" lay-append-to="body">
														<c:forEach items="${config.queryTypeList}" var="dict">
															<option value="${fns:escapeHtml(dict.value)}" ${fns:escapeHtml(dict.value)==column.queryType?'selected':''} title="${dict.description}">${fns:escapeHtml(dict.label)}</option>
														</c:forEach>
													</select>
												</td>
												<td>
													<select name="columnList[${vs.index}].showType" class="required nativeSelect" lay-append-to="body">
														<c:forEach items="${config.showTypeList}" var="dict">
															<option value="${dict.value}" ${dict.value==column.showType?'selected':''} title="${dict.description}">${dict.label}</option>
														</c:forEach>
													</select>
												</td>
												<td>
													<input type="text" name="columnList[${vs.index}].dictType" value="${column.dictType}" maxlength="200" class="form-control"/>
												</td>
												<td>
													<input type="text" name="columnList[${vs.index}].sort" value="${column.sort}" maxlength="200" class="required form-control digits"/>
												</td>
											</tr>
										</c:forEach>
										</tbody>
									</table>
								</div>
							<div class="form-actions">
								<shiro:hasPermission name="gen:genTable:edit">
								<input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;
								</shiro:hasPermission>
								<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
							</div>
						</form:form>
					</c:otherwise>
				</c:choose>
			</div>
		</div>
	</div>
</body>
</html>
